package cn.bs.busuo.content.service.impl;

import cn.bs.busuo.common.enumerator.ServiceCode;
import cn.bs.busuo.common.ex.ServiceException;
import cn.bs.busuo.content.dao.persist.repository.CommentRepository;
import cn.bs.busuo.content.pojo.vo.CommentHotelByCheckVO;
import cn.bs.busuo.content.pojo.vo.CommentSightByCheckVO;
import cn.bs.busuo.content.service.CommentService;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author: Feng
 * @since: 2023/12/9
 */
@Repository
public class CommentServiceImpl implements CommentService {

    @Autowired
    private CommentRepository commentRepository;


    //----------酒店部分

    //查看未审核的酒店文章评论
    @Override
    public String listHotelNotCheck() {
        List<CommentHotelByCheckVO> commentHotelByCheckVOS = commentRepository.listHotelNotCheck();
        if (commentHotelByCheckVOS.size() == 0){
            throw new ServiceException(ServiceCode.OK,"暂时还没有未审核的评论");
        }
        String json = JSON.toJSON(commentHotelByCheckVOS).toString();
        return json;
    }

    //审核酒店文章评论通过
    @Override
    public void hotelCommentCheck(List<Long> ids) {
        int i = commentRepository.hotelCommentCheck(ids);
        if (i == 0){
            throw new ServiceException(ServiceCode.ERROR_UPDATE,"修改失败");
        }
    }

    //审核酒店文章评论不通过
    @Override
    public void hotelCommentNotCheck(List<Long> ids) {
        int i = commentRepository.hotelCommentNotCheck(ids);
        if (i == 0){
            throw new ServiceException(ServiceCode.ERROR_UPDATE,"修改失败");
        }
    }


    //----------景点部分


    //查看未审核的景点文章评论
    @Override
    public String listSightNotCheck() {
        List<CommentSightByCheckVO> commentSightByCheckVOS = commentRepository.listSightNotCheck();
        if (commentSightByCheckVOS.size() == 0){
            throw new ServiceException(ServiceCode.OK,"暂时还没有未审核的评论");
        }
        String json = JSON.toJSON(commentSightByCheckVOS).toString();
        return json;
    }

    //审核景点文章评论通过
    @Override
    public void sightCommentCheck(List<Long> ids) {
        int i = commentRepository.sightCommentCheck(ids);
        if (i == 0){
            throw new ServiceException(ServiceCode.ERROR_UPDATE,"修改失败");
        }
    }

    //审核景点文章评论不通过
    @Override
    public void sightCommentNotCheck(List<Long> ids) {
        int i = commentRepository.sightCommentNotCheck(ids);
        if (i == 0){
            throw new ServiceException(ServiceCode.ERROR_UPDATE,"修改失败");
        }
    }
}
